Networking and Comms

Designing the board.


For this week assigment, I wanted to take my old helloboard and make it communicate with another board, the Helloboard will serve as a master and the other board, wich will only contain an ISP header, an attiny44, a res RES and a LED will be my slave board. The board design part will be super easy and quick so I can have time to fully comprehend how to communicate using the SoftwareSerial library on the arduino IDE.

As usual let's start by opening up Eagle and creating a new schematics. Once this is done, just import all you component for your board using the "add" command:





Once youv'e import all of your components, you can link them using the "net" command or by naming them with each other same names using the "name and label" command. This allow for a more clean and comprehensible schematic.





Let's take a look at our scheatics cause you may realize some things that needs awser. First of all, you can see that there is no power being supply to the board, why's that? Because since we will be using this board at our slave, it will always have to be connected to our master board to work, so the board will be supply by our master via the ISP headers. Also, on the same matther,this mean that I will have to jump my fabisp to let him be able to supply the slave during it's programmation.

An other interesting thing to see here is that the mosi and miso pins will play an important role on this board, not only the pins give us the ability to program the board, like any of the other board we made, but they are the pins we will use the communicate between the master and the slave, the ISP headers now not only have the purpose of programming the board, but will also serve as the communication and power bus between our two boards.



Now that our schematics are done (see electronic design for the master), we can go on and generate our board by pressing the "generate/switch to board" button, all the component will apear, link by a yellow line, you can now place them as you wish and set your DRC tool to get ready for the autorouter, once this is done, just start the autorouter, make sure your'e set for a one layer board and watch it do it's own thing!









Now that are board is done we can get ready for preparing the Gcode and mill the board.

Preping the Gcode and Milling the board


To generate our toolpath, we will use Flatcam, but before even opening the program, we need to export our board as a gerber file for the traces and an excellon file for the holes. To do so, you need to go into the CAM processor tool inside EAGLE, you can load a local job for the gerber file and the excellon file.



Then just press the button process job and your good to go!

Once in Flatcam, you can open your gerber file by going into file, open gerber. once it's done it should look like that:



Now you can select your gerber job and go into the selected tab, here are my settings, I use a 0.0056" tool, and will make a 7 passes job, I combine them to fit them into one job.



you can now go back into the project tab and select the newly created .iso job. here you can prepare your cutting parameters.



You can then export this job into a Gcode file.
The Gcodes are ready! let's go mill!

For the milling process make sure that your machine is correctly home and that the board is level on the machine bed, for the rest, same process as usual! I did not have my camera during the milling process, but here are the results!



Soldering the board and Programming the board



I don't have much new to say about my soldering technics, other than the fact that I bought myself an amazing and cheap microscope that serve amazingly to verify my pcb's trace and solder. The microscope can do 10x to 200x zoom and is plug via USB to your phone or compujter and the image quality is amazing, here is an exemple!



This is a life changer! no more looking half an hour for short circuit!



Here is my board, we can now start looking at our code!

Master Code



 
        #include <.SoftwareSerial.h> // 


// constants won't change. They're used here to set pin numbers:
const int buttonPin = 3;     // the number of the pushbutton pin
const int ledPin = 8;
const int rx = 5;
const int tx = 6;
bool flashing = false;

SoftwareSerial mySerial(rx, tx);

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

  mySerial.begin(4800);

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);




  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == LOW) {

    flashing = !flashing;

    if (flashing) {
      mySerial.write(1);
    }

    delay(1000);
  }
  if (flashing ) {
    if (mySerial.available() > 0) {
      mySerial.read();
      digitalWrite (ledPin, HIGH);
      delay (1000);
      digitalWrite (ledPin, LOW);
      mySerial.write(1);

    }
  }
}  



      


As usual, we start by importing the library we will need inside our code (In our case SoftwareSerial) and by defining our global variable, for the master, we have the button pin, the led pin, the transmit pin and the receiver pin, these are all integer that will not change during the course of the code, so we set them as

const int (name) = pinNumber

We also need a boolean inside our code, a boolean is a true or false statement. In our case, the boolean will look if the LED is flashing, as a default setup, we set it to false.

bool flashing = false;

Next, we define wich pin will be use for our Software Serial



We will also need to set up a variable that WILL change during the course of the code, the variable will be use to check the button state, if it's HIGH OR LOW.

int buttonState = 0;

Next thing we need to do is write our setup phase, we really don't need much in this part of the code, we will first start our Serial and then we will initialize the pushbutton as an input, that's all!



Next is the loop:



Before I can explain the code to you, I must speak to you about what we call a pull-up and a pull-down resistor. A pull down resistor uses our pushbutton to send 5V to our button pin. With a pull-up resistor our button pin is floating and so goes up to 5V when the pressbutton is pressed, the pin is then link to the ground and the 10K resistor eat all the voltage so we can read 0V to our pin I designed my helloboard using a pull-up resistor that means that in my Code, I will have to use a (LOW STATE) on my button state for me to send 5V to it.



Ok, now let's look at the loop, here we mainly do two things, first we look at our button state, if the button state is LOW (so ON), we invert the flashing variable using this command:

flashing = !flashing;

this tell that if flashing is false, it is now true. And vice-versa.

Next we tell that if flashing is true, (since it's a boolean we don't acutally have to write TRUE OR FALSE, just writing flashing check if the fact is true.) we want to write to serial the value 1. then we give a delay. This sent all we need to our slave.

The next part is avout receiving from the slave, we again look at if flashing is true, if it is, we look if my serial is avaible and over 0, if it is over 0, we open our led and we rewrite our serial with a 1.

Slave code




        


          #include <.SoftwareSerial.h>





const int ledPin = 8; // the pin that the LED is attached to
const int rx = 6;
const int tx = 5;

SoftwareSerial mySerial(rx, tx);

void setup() {
  // initialize serial communication:
  mySerial.begin(4800);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (mySerial.available() > 0) {
    mySerial.read ();
     digitalWrite (ledPin, HIGH);
     delay (1000);
     digitalWrite (ledPin, LOW);
     mySerial.write(1);


  }
}




The slave code does basicly the same thing but without the button, we define our pins, initialize our SerialSoftware, set our LED as an output, read our serial, check if the value coming from it is over 0 and write 1 to our serial so the LED of the master can open. EASY PEASY!



You can find my files here!